package com.example.demo.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @author pinp
 */
@Data
public class Result implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = 0;
    public static final int ERROR = 1;

    private int errCode;
    private String msg;
    private Object data;

    public Result(int errCode, String msg, Object data) {
        this.errCode = errCode;
        this.msg = msg;
        this.data = data;
    }

    public static Result ok() {
        return new Result(SUCCESS, "Success", null);
    }

    public static Result ok(Object data) {
        return new Result(SUCCESS, "Success", data);
    }

    public static Result msg(String msg) {
        return new Result(SUCCESS, msg, null);
    }

    public static Result error() {
        return new Result(ERROR, "Error", null);
    }

    public static Result error(String msg) {
        return new Result(ERROR, msg, null);
    }

    public static Result error(int errCode, String msg) {
        return new Result(errCode, msg, null);
    }

}
